<template>
  <div class="contents">
    <PanelTitle title="页面停留" />
    <div ref="maps" class="maps mt"></div>
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import echarts from "@/components/echarts";
import PanelTitle from "../../component/PanelTitle.vue";
import http from "@/api/http";
import { env } from "@/utils/env";
import { fitChartSize } from "@/utils/dataUtil.js";
import { useVisitStore } from "@/stores/visit";
const visitStore = useVisitStore()
const maps = ref(null);
onMounted(async () => {
  let res = await http({
    url: env.VITE_ZHER_DATA_CENTER + "/farming/user/visit/duration/statist/list",
    method: "get",
    params: { type: 2 },
  });

  let dict = visitStore.visitType

  let yData = res.data.map((item) => {
    return dict[item.sysType];
  });

  let seriesData = res.data.map((item) => {
    return item.duration;
  });

  var myChart = echarts.init(maps.value);

  myChart.setOption({
    tooltip: {
      show: true,
      trigger: "axis",
    },
    grid: {
      left: "3%",
      right: "10%",
      bottom: "10%",
      top: "5%",
      containLabel: true,
    },
    title: {
      text: "单位：min",
      textStyle: {
        color: "#fff",
        fontWeight: 500,
        fontSize: fitChartSize(9),
      },
      right: fitChartSize(10),
    },
    xAxis: [
      {
        type: "value",
        splitNumber: 4,
        splitLine: {
          lineStyle: {
            color: "rgba(255,255,255,0.09)", //线条颜色
            // type: "dashed", //线条样式，默认是实现，dashed是虚线
          },
        },
        min: 0,
        axisLabel: {
          textStyle: {
            color: "#7AFFFD",
            fontSize: fitChartSize(9),
          },
        },
      },
    ],
    yAxis: [
      {
        type: "category",
        data: yData,
        axisLabel: {
          textStyle: {
            color: "#7AFFFD",
            fontSize: fitChartSize(9),
          },
        },
        axisPointer: {
          type: "shadow",
        },
        axisTick: {
          show: false,
        },
        axisLine: {
          show: false,
        },
      },
    ],
    series: [
      {
        type: "bar",
        barWidth: fitChartSize(14),
        backgroundStyle: {
          color: "rgba(110, 193, 244, 1)",
        },
        itemStyle: {
          normal: {
            // label: {
            //   show: true,
            //   position: "top",
            //   textStyle: {
            //     color: "#fff",
            //     fontSize: 10,
            //   },
            // },
            color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
              {
                offset: 0,
                color: "rgba(250, 216, 112, 0.2)",
              },
              {
                offset: 1,
                color: "rgba(250, 216, 112, 1)",
              },
            ]),
          },
        },
        data: seriesData,
      },
    ],
  });
});
</script>

<style scoped lang="scss">
.contents {
  background: linear-gradient(
    to bottom,
    rgba(5, 79, 99),
    rgba(5, 79, 99, 0.1),
    rgba(5, 79, 99)
  );
  border-radius: vh(8);
  border: vh(1) solid rgba(6, 112, 180, 1);
  .mt {
    margin-top: vh(-40);
  }
}
.maps {
  height: vh(190);
  width: 100%;
}
</style>